<%--
  Created by IntelliJ IDEA.
  User: zhongge
  Date: 2025/8/15
  Time: 20:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>学生信息列表</title>
    <style>
        table { border-collapse: collapse; width: 80%; margin: 20px auto; }
        th, td { border: 1px solid #ccc; padding: 10px; text-align: center; }
        th { background-color: #f2f2f2; }
        .btn { padding: 5px 10px; text-decoration: none; color: #fff; border-radius: 3px; }
        .add-btn { background-color: #4CAF50; }
        .edit-btn { background-color: #2196F3; }
        .delete-btn { background-color: #f44336; }
        .header { text-align: center; margin: 20px; }
        .search-btn { background-color: #ff9800; } /* 橙色 - 查询（新颜色） */
    </style>
</head>
<body class="header">
    <div class="header">
        <h1>学生信息管理</h1>
        <div class="action-bar">
            <a href="student/add.jsp" class="btn add-btn">添加新学生</a>

            <!-- 移动到添加按钮旁边的ID查询表单 -->
            <form method="post" action="${pageContext.request.contextPath}/getById" style="display: inline;">
                <input type="number" name="searchId" placeholder="输入学生ID查询"
                       value="${param.searchId != null ? param.searchId : ''}">
                <button type="submit" class="btn search-btn">查询</button>
                <c:if test="${param.searchId != null}">
                    <a href="${pageContext.request.contextPath}/getById" class="btn reset-btn">清除查询</a>
                </c:if>
            </form>
        </div>
    </div>


    <table>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>生日</th>
        <th>地址</th>
        <th>备注</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${students}" var="student">
        <tr>
            <td>${student.id}</td>
            <td>${student.name}</td>
            <td>${student.age}</td>
            <td>${student.sex == 1 ? '男' : '女'}</td>
            <td>
                    ${student.birthday}
                <%--<fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd"/>--%>
            </td>
            <td>${student.address}</td>
            <td>${student.remark}</td>
            <td>
                <a href="${pageContext.request.contextPath}/update?id=${student.id}" class="btn edit-btn">编辑</a>
                <%--超链接是一个get请求--%>
                <a href="${pageContext.request.contextPath}/delete?id=${student.id}" class="btn delete-btn"
                   onclick="return confirm('确定要删除吗？')" >删除</a>
            </td>
        </tr>
    </c:forEach>
    </table>
</body>
</html>

